package com.nidu.demo.file.executor.query;

import com.alibaba.cola.dto.MultiResponse;
import com.nidu.demo.common.enums.FileStorageTypeEnum;
import com.nidu.demo.file.convertor.FileConfigConvertor;
import com.nidu.demo.file.convertor.FileConfigCriteriaConvertor;
import com.nidu.demo.file.dto.FileConfigCO;
import com.nidu.demo.file.dto.FileConfigListQry;
import com.nidu.demo.file.gateway.FileConfigGateway;
import com.nidu.demo.file.model.FileConfig;
import com.nidu.demo.file.model.FileConfigCriteria;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 文件配置列表查询执行器
 *
 * @author auto
 */
@Component
@RequiredArgsConstructor
public class FileConfigListQryExe {

    private final FileConfigGateway gateway;
    private final FileConfigConvertor convertor;
    private final FileConfigCriteriaConvertor criteriaConvertor;

    /**
     * 查询文件配置列表
     *
     * @param qry 查询条件
     * @return 文件配置列表
     */
    public MultiResponse<FileConfigCO> execute(FileConfigListQry qry) {
        // 1. 转换查询条件
        FileConfigCriteria criteria = criteriaConvertor.toDataObject(qry);
        
        // 2. 执行查询
        List<FileConfig> fileConfigs = gateway.listByCondition(criteria);
        
        // 3. 转换为DTO
        List<FileConfigCO> fileConfigCOS = convertor.toClientObjects(fileConfigs);
        
        return MultiResponse.of(fileConfigCOS);
    }
}
